home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
TextEdit
/
TextEditObject.h
< prev
next >
Wrap
Text File
|
2000-06-23
|
6KB
|
172 lines
// TextEditObject.h
#ifndef TextEditObject_h
#define TextEditObject_h
#ifndef TextEditUser_h
#include "TextEditUser.h"
#endif
#ifndef ConstData_h
#include "ConstData.h"
#endif
#ifndef Rectangle_h
#include "Rectangle.h"
#endif
#ifndef Face_h
#include "Face.h"
#endif
#ifndef SourceMode_h
#include "SourceMode.h"
#endif
#ifndef GrafPortObject_h
#include "GrafPortObject.h"
#endif
#ifndef TextEditCutter_h
#include "TextEditCutter.h"
#endif
#ifndef TextEditPaster_h
#include "TextEditPaster.h"
#endif
#ifndef Overflow_h
#include "Overflow.h"
#endif
class TextEditObject: public TextEditUser
{
private:
TEHandle te;
// not implemented:
TextEditObject( const TextEditObject& );
void operator=( const TextEditObject& );
TERec& Record() { return **te; }
const TERec& Record() const { return **te; }
Rectangle& Destination() { return static_cast<Rectangle&>( Record().destRect ); }
const Rectangle& Destination() const { return static_cast<const Rectangle&>( Record().destRect ); }
Rectangle& View() { return static_cast<Rectangle&>( Record().viewRect ); }
const Rectangle& View() const { return static_cast<const Rectangle&>( Record().viewRect ); }
public:
TextEditObject( GrafPortObject&,
const Rect& screenArea,
uint16 wrapWidth );
~TextEditObject() { TEDispose( te ); }
TEHandle TextEditHandle() { return te; }
uint32 WrapWidth() const { return Destination().Width(); }
void SetWrapWidth( uint16 );
Rectangle ScreenArea() const { return View(); }
void SetScreenArea( const Rectangle& );
void DisplayAt( GrafPortObject&,
Rectangle area,
PointObject scroll );
uint16 Length() const { return Asuint16( Record().teLength ); }
uint16 LineCount() const { return Asuint16( Record().nLines ); }
uint16 LineHeight() const { return Asuint16( Record().lineHeight ); }
const uint16 *LineStarts() const { return reinterpret_cast<const uint16 *>( Record().lineStarts ); }
bool Active() const { return Record().active != 0; }
void Activate() { TEActivate( te ); }
void Deactivate() { TEDeactivate( te ); }
void Type( uint8 key );
enum SpecialKey
{
backspace = 0x08,
returnKey = 0x0d,
leftArrow = 0x1c,
rightArrow = 0x1d,
upArrow = 0x1e,
downArrow = 0x1f
};
void DeleteBackward() { TEKey( backspace, te ); }
void DeleteForward();
void TypeReturn() { Type( returnKey ); }
void LeftArrow() { TEKey( leftArrow, te ); }
void RightArrow() { TEKey( rightArrow, te ); }
void UpArrow() { TEKey( upArrow, te ); }
void DownArrow() { TEKey( downArrow, te ); }
void SetText( ConstData text );
ConstData Text() const { return ConstData( *Record().hText, Length() ); }
void Idle() const { TEIdle( te ); }
static uint32 IdlePeriod() { return GetCaretTime() + 1; }
void Click( PointObject p, bool shift ) { TEClick( p, shift, te ); }
URange16 Selection() const { return URange16( Asuint16( Record().selStart ),
Asuint16( Record().selEnd ) ); }
void SetSelection( URange16 r ) { TESetSelect( r.Start(), r.End(), te ); }
ConstData SelectedText() const { return ConstData( *Record().hText + Record().selStart,
*Record().hText + Record().selEnd ); }
URange16 DefaultSelection() const { return URange16( 0, 0 ); }
URange16 AllSelection() const { return URange16( 0, Length() ); }
enum AlignmentType
{
standard = teFlushDefault,
center = teCenter,
right = teFlushRight,
left = teFlushLeft
};
AlignmentType Alignment() const { return static_cast<AlignmentType>( Record().just ); }
void SetAlignment( AlignmentType a ) { TESetAlignment( a, te ); }
void Draw( const Rect& visible ) const { Assert( Port().IsCurrent() ); TEUpdate( &visible, te ); }
void Recalculate() { TECalText( te ); }
PointObject Scroll() const;
void SetScroll( PointObject );
void ScrollAutomatically() { TEAutoView( true, te ); }
void DontScrollAutomatically() { TEAutoView( false, te ); }
void RevealSelection() { TESelView( te ); }
void DeleteSelection() { TEDelete( te ); }
void ReplaceSelection( ConstData );
void Cut() { TextEditCutter().Cut( te ); }
void Copy() const { TextEditCutter().Copy( te ); }
void Paste() { TextEditPaster().Paste( te ); }
static bool CanPaste() { return TextEditClipboard::The().Length() > 0; }
FontNumber Font() const { return FontNumber( Record().txFont ); }
void SetFont( FontNumber font ) { Record().txFont = font.Value(); }
FontSize Size() const { return FontSize( uint16( Record().txSize ) ); }
void SetSize( FontSize size ) { Record().txSize = int16( size.Value() ); }
::Style Style() const { return Record().txFace; }
void SetStyle( ::Style style ) { Record().txFace = style; }
SourceMode Mode() const { return SourceMode( Record().txMode ); }
void SetMode( SourceMode mode ) { Record().txMode = mode.Value(); }
::Face Face() const { return ::Face( Font(), Size(), Style() ); }
void SetFace( const ::Face& face );
GrafPortObject& Port() const { return static_cast<GrafPortObject&>( *Record().inPort ); }
void SetPort( GrafPortObject& port ) { Record().inPort = &port; }
};
#endif